package com.junjie.services.impl;

import com.junjie.dao.RoomDao;
import com.junjie.entity.Room;
import com.junjie.services.RoomService;
import com.junjie.utils.CommonParams;
import com.junjie.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomDao roomDao;

    //根据根据信息来查询房间
    @Override
    public List<Room> selectSearchRoom(Room room) {
        return roomDao.getSearchRoom(room);
    }

    //插入房间的信息
    @Override
    public CommonResult<Integer> insertRoom(Room room) {
        return new CommonResult<>(CommonParams.SUCCESS, "房间添加成功！", roomDao.insertRoom(room));
    }

    //修改一间房间的信息
    @Override
    public CommonResult<Integer> updateRoomById(Room room) {
        return new CommonResult<>(CommonParams.SUCCESS, "房间信息修改成功！", roomDao.updateAndDeleteRoomById(room));
    }

    //删除一间房间的信息
    @Override
    public CommonResult<Integer> deleteRoomById(Integer id) {
        Room room = new Room();
        room.setId(id);
        room.setStatus(0);
        return new CommonResult<>(CommonParams.SUCCESS, "房间删除成功！",roomDao.updateAndDeleteRoomById(room));
    }
}
